class editor_gui :
    def __init__ ( self , mediator ) :
        self . _mediator = mediator
        self . _prototype = _editor_prototype ( mediator )
        self . _created_button = None
        self . _created_frame = None
        self . _created_label = None
        self . _application_window = None
    def show_editor ( self ) :
        self . _create_frame ( )
        self . _add_menu_button ( )
        self . _prototype . show_editor ( )
    def hide_editor ( self ) :
        self . _destroy_frame ( )
        self . _prototype . hide_editor ( )
    def application_window_reply ( self , window ) :
        self . _application_window = window
        self . _prototype . application_window_reply ( window )
    def gui_create_button_reply ( self , button ) :
        self . _created_button = button
    def gui_create_entry_reply ( self , entry ) :
        self . _prototype . gui_create_entry_reply ( entry )
    def gui_create_frame_reply ( self , frame ) :
        self . _created_frame = frame
        self . _prototype . gui_create_frame_reply ( frame )
    def gui_create_label_reply ( self , label ) :
        self . _created_label = label
        self . _prototype . gui_create_label_reply ( label )
    def gui_create_text_reply ( self , text ) :
        self . _prototype . gui_create_text_reply ( text )
    def gui_entry_text_reply ( self , text ) :
        self . _prototype . gui_entry_text_reply ( text )
    def add_title_label_to_editor ( self , base_name ) :
        self . _add_title ( base_name )
    def _create_frame ( self ) :
        self . _mediator . application_window_request ( )
        self . _mediator . gui_create_frame_request ( self . _application_window )
        self . _frame = self . _created_frame
        self . _mediator . gui_pack  ( self . _frame , side = self . _mediator . gui_side_top ( ) )
    def _destroy_frame ( self ) :
        self . _mediator . gui_destroy_frame ( self . _frame )
    def _add_title ( self , base_name ) :
        self . _mediator . gui_create_label_request ( self . _frame , self . _mediator . localization_editor_title ( ) + ' ' + base_name )
        self . _mediator . gui_pack ( self . _created_label , side = self . _mediator . gui_side_top ( ) )
    def _add_menu_button ( self ) :
        self . _mediator . gui_create_button_request \
            ( self . _frame
            , self . _mediator . localization_editor_menu_button ( )
            , self . _mediator . on_editor_menu_button
            )
        self . _mediator . gui_pack  ( self . _created_button , side = self . _mediator . gui_side_bottom ( ) )
    def add_mark_to_editor_contents ( self ) :
        self . _prototype . add_mark_to_editor_contents ( )
    def add_text_to_editor_contents ( self , text ) :
        self . _prototype . add_text_to_editor_contents ( text )
    def add_entry_to_editor_contents ( self ) :
        self . _prototype . add_entry_to_editor_contents ( )
    def delete_entry_from_editor_contents ( self ) :
        self . _prototype . delete_entry_from_editor_contents ( )
    def set_editor_content_entry_string ( self , txt ) :
        self . _prototype . set_editor_content_entry_string ( txt )
    def set_editor_status_string ( self , text ) :
        self . _prototype . set_editor_status_string ( text )
    def request_editor_entry_string ( self ) :
        self . _prototype . request_editor_entry_string ( )
    def remove_all_marks_from_editor_contents ( self ) :
        self . _prototype . remove_all_marks_from_editor_contents ( )
    def delete_text_from_last_mark_to_end_of_editor_contents ( self ) :
        self . _prototype . delete_text_from_last_mark_to_end_of_editor_contents ( )
    def request_is_any_marks_left_in_editor_contents ( self ) :
        self . _prototype . request_is_any_marks_left_in_editor_contents ( )

# PROTOTYPE, NOT TEST-COVERED!

class _editor_prototype :
    def __init__ ( self , mediator ) :
        self . _mediator = mediator
        self . _application_window = None
        self . _created_frame = None
        self . _created_label = None
        self . _created_text = None
        self . _entry_text_replied = None
    def application_window_reply ( self , window ) :
        self . _application_window = window
    def gui_create_entry_reply ( self , entry ) :
        self . _created_entry = entry
    def gui_create_frame_reply ( self , frame ) :
        self . _created_frame = frame
    def gui_create_label_reply ( self , label ) :
        self . _created_label = label
    def gui_create_text_reply ( self , text ) :
        self . _created_text = text
    def gui_entry_text_reply ( self , text ) :
        self . _entry_text_replied = text
    def show_editor ( self ) :
        self . _mediator . application_window_request ( )
        self . _all_entry_marks = [ ]
        self . _next_mark_id = 0
        self . _root = self . _application_window
        self . _mediator . gui_create_frame_request ( self . _root )
        self . _frame = self . _created_frame
        self . _mediator . gui_pack ( self . _frame )
        self . _mediator . gui_create_text_request ( self . _frame )
        self . _text = self . _created_text
        self . _mediator . gui_pack ( self . _text )
        self . _mediator . gui_add_string_to_text_widget ( self . _text , 'press ctrl-f5 or f5\n' )
        self . _mediator . gui_disable_text_edit ( self . _text )
        self . _mediator . gui_create_label_request ( self . _frame , 'welcome to the editor' )
        self . _label = self . _created_label
        self . _mediator . gui_pack ( self . _label )
        self . _mediator . activate_editor_state_creating_new_query ( )
    def hide_editor ( self ) :
        self . _mediator . gui_destroy_frame ( self . _frame )
    def add_mark_to_editor_contents ( self ) :
        mark_name = 'entry_mark_%i' % self . _next_mark_id
        self . _mediator . gui_enable_text_edit ( self . _text )
        self . _mediator . gui_add_mark_to_text_widget ( self . _text , mark_name )
        self . _mediator . gui_disable_text_edit ( self . _text )
        self . _all_entry_marks += [ mark_name ]
        self . _next_mark_id += 1
    def add_text_to_editor_contents ( self , text ) :
        self . _mediator . gui_enable_text_edit ( self . _text )
        self . _mediator . gui_add_string_to_text_widget ( self . _text , text )
        self . _mediator . gui_disable_text_edit ( self . _text )
    def add_entry_to_editor_contents ( self ) :
        self . _mediator . gui_create_entry_request ( self . _text , None )
        self . _entry = self . _created_entry
        self . _mediator . gui_enable_text_edit ( self . _text )
        self . _mediator . gui_add_widget_to_text_widget ( self . _text , self . _entry )
        self . _mediator . gui_disable_text_edit ( self . _text )
        self . _mediator . gui_move_focus_to ( self . _entry )
    def delete_entry_from_editor_contents ( self ) :
        self . _mediator . gui_remove_widget_from_text_widget ( self . _text , self . _entry )
        self . _mediator . gui_destroy_entry ( self . _entry )
    def set_editor_content_entry_string ( self , txt ) :
        self . _mediator . gui_set_entry_text ( self . _entry , txt )
    def set_editor_status_string ( self , text ) :
        self . _mediator . gui_set_label_text ( self . _label , text )
    def request_editor_entry_string ( self ) :
        self . _mediator . gui_entry_text_request ( self . _entry )
        s = self . _entry_text_replied
        self . _mediator . receive_editor_entry_string ( s )
    def remove_all_marks_from_editor_contents ( self ) :
        self . _mediator . gui_enable_text_edit ( self . _text )
        while len ( self . _all_entry_marks ) > 0 :
            self . _mediator . gui_remove_mark_from_text_widget ( self . _text , self . _all_entry_marks . pop ( ) )
        self . _mediator . gui_disable_text_edit ( self . _text )
    def delete_text_from_last_mark_to_end_of_editor_contents ( self ) :
        mark_name = self . _all_entry_marks . pop ( )
        self . _mediator . gui_enable_text_edit ( self . _text )
        self . _mediator . gui_delete_text_from_mark_to_end_of_text_widget ( self . _text , mark_name )
        if len ( self . _all_entry_marks ) == 0 :
            self . _mediator . gui_add_string_to_text_widget ( self . _text , '\n' )
        self . _mediator . gui_remove_mark_from_text_widget ( self . _text , mark_name )
        self . _mediator . gui_disable_text_edit ( self . _text )
    def request_is_any_marks_left_in_editor_contents ( self ) :
        self . _mediator . receive_is_any_marks_left_in_editor_contents ( len ( self . _all_entry_marks ) )
